# -*- mode: org; fill-column: 80; -*-
#+TITLE: REPL Usage
#+AUTHOR: Zelphir Kaltstahl
#+STARTUP: content indent align inlineimages entitiesplain nologdone nologreschedule nologredeadline nologrefile
#+TODO: TODO WIP | DONE
#+DATE: [2022-03-17 Do]
#+LANGUAGE: English
#+PRIORITIES: A C C

* Starting the REPL
:PROPERTIES:
:custom_id: starting-the-repl
:END:

#+begin_src shell
sml
#+end_src

* Show sml command help
:PROPERTIES:
:custom_id: show-sml-command-help
:END:

#+begin_src shell :results output verbatim drawer replace :export both
sml -h
#+end_src

#+RESULTS:
:results:
Standard ML of New Jersey v110.79 [built: Sat Oct 26 12:27:04 2019]
sml [rtsargs] [options] [files]

  rtsargs:
    @SMLload=<h>     (start specified heap image)
    @SMLalloc=<s>    (specify size of allocation area)
    @SMLcmdname=<n>  (set command name)
    @SMLquiet        (load heap image silently)
    @SMLverbose      (show heap image load progress)
    @SMLobjects      (show list of executable objects)
    @SMLdebug=<f>    (write debugging info to file)

  files:
    <file>.cm        (CM.make or CM.autoload)
    -m               (switch to CM.make)
    -a               (switch to CM.autoload; default)
    <file>.sig       (use)
    <file>.sml       (use)
    <file>.fun       (use)

  options:
    -D<name>=<v>     (set CM variable to given value)
    -D<name>         (set CM variable to 1)
    -Uname           (unset CM variable)
    -C<control>=<v>  (set named control)
    -H               (produce complete help listing)
    -h               (produce minimal help listing)
    -h<level>        (help with obscurity limit)
    -S               (list all current settings)
    -s<level>        (limited list of settings)
    -E               (list all environment variables)
    -e<level>        (limited list of environment variables)

  SML/NJ controls:
   Compilation Manager (CM):
:end:

* Inside REPL
:PROPERTIES:
:custom_id: inside-repl
:END:

** Loading a program
:PROPERTIES:
:custom_id: loading-a-program
:END:

Corresponding to ~(load "file.scm")~ in Scheme:

#+begin_src sml
use "filename";
#+end_src

** Opening a library

Opening a library will introduce its bindings into the current environment:

#+begin_src sml
open "filename";
(* or *)
open structure_name;
#+end_src

** Directories
:PROPERTIES:
:custom_id: directories
:END:

*** Current directory
:PROPERTIES:
:custom_id: current-directory
:END:

#+begin_src sml
OS.FileSys.getDir();
#+end_src

*** Change directory
:PROPERTIES:
:custom_id: change-directory
:END:

#+begin_src sml
OS.FileSys.chDir("filename");
#+end_src


* Use compilation manager
:PROPERTIES:
:custom_id: compilation-manager
:END:

#+begin_src sml
CM.make "file.cm";
#+end_src

Find more info at [[https://www.smlnj.org/doc/CM/index.html]].

* Exiting the REPL
:PROPERTIES:
:custom_id: exiting-the-repl
:END:

Either use =C-d= or run the following code:

#+begin_src sml
OS.Process.exit(OS.Process.success);
#+end_src

* More info
:PROPERTIES:
:custom_id: more-info
:END:

Some links:

+ [[https://www.smlnj.org/doc/FAQ/usage.html]]
